#ifndef GAMECONTROL_H
#define GAMECONTROL_H

#include"widget.h"
#include<QObject>
#include <QGraphicsView>
#include<QGraphicsScene>
#include<QGraphicsPixmapItem>
#include<QTimer>
#include<QRectF>
#include<QToolButton>
#include<QMediaPlayer>
#include<QUrl>
#include"manblue.h"
#include"manred.h"

class GameControl : public QObject
{
    //单例
    GameControl(QWidget* parent = nullptr);
    static GameControl* instance;
public:
    //获取单例
    static GameControl* Instance()
    {
        if(instance == nullptr)
        {
            return instance = new GameControl(Widget::widget);
        }
        return instance;
    }

    //游戏初始化
    void GameInit();
    void LoadStartScene();//加载开始场景
    void LoadGameScene();//游戏场景加载

    //游戏逻辑定时器开启
    void GameStart();

    //游戏逻辑定时器关闭
    void GameOver();


    static const int playerMoveTimer = 10;
    static const int platformTimer = 20;

    //屏幕宽高
    static const int ScreenWidth = 1347;
    static const int ScreenHeight = 1009;

    void addPlatform(double x,double y,int width,int height);

    //容器
    QList<QRectF> platforms;//平台组合
    QList<int> mKeyList;//按键组合

    double vyblue;
    double vy1blue;
    double gravity;
    float mMoveSpeed;

    bool isJumpingblue = false;

    double vyred;
    double vy1red;

    bool isJumpingRed = false;

    void move();
    void jumpblue();
    void jumpred();
    void updatePosition();
    void boundaryJudge();//边界判断
    void detectCollisions();//检测下部分碰撞
    void downCollisions();//检测上部分碰撞并反弹
    void watergreenJudge();//绿水判断
    void waterRedJudge();//红水判断
    void downblue();
    void downred();
    void changePixmapBlue();
    void changePixmapRed();


protected:

    //游戏视图
    QGraphicsView mGameView;

    //场景
    QGraphicsScene mGameScene;
    QGraphicsScene mStartScene;
    QGraphicsScene mDeathScene;
    QGraphicsScene mSuccessScene;

    //元素
    QGraphicsPixmapItem mBackground;//背景
    QGraphicsPixmapItem mWaterRed;//红水
    QGraphicsPixmapItem mWaterBlue;//蓝水
    QGraphicsPixmapItem mWaterGreen;//绿水
    QGraphicsPixmapItem mStrategyUpdown;//机关横杠
    QGraphicsPixmapItem mDoorBlue;
    QGraphicsPixmapItem mDiamondBlue;//蓝钻
    ManBlue mManBlue;
    ManRed mManRed;//红人


    //定时器
    QTimer* mPlayerMoveTimer;//冰人移动
    //QTimer* mJumpTimer;//跳跃定时器
    QTimer* mFormTimer;//平台定时器



};



#endif // GAMECONTROL_H
